import xlrd
import tests.Assertion_Generation_Tool

# workbook =xlrd.open_workbook('testcast.xls')
# allSheetName = workbook.sheet_names()
# sheet1name = workbook.sheet_names()[0]

# sheet1_conntent2 =workbook.sheet_by_index(0)
# sheet1_conntent1 = workbook.sheet_by_name('接口自动化')
# print(sheet1_conntent2.name, sheet1_conntent2.nrows, sheet1_conntent2.ncols)
# rows = sheet1_conntent2.row_values(0);  # 获取第一行内容
# cols = sheet1_conntent2.col_values(1);  # 获取第二列内容
# print(rows)
# print(cols)
# print(int(sheet1_conntent2.cell(1, 0).value))
# print(sheet1_conntent2.cell_value(2, 2))
# print(sheet1_conntent2.row(2)[2].value)
# Tips: python读取excel中单元格的内容返回的有5种类型 [0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error]
# print(sheet1_conntent2.cell(2, 6).ctype);
def Interface_Name(path,executions):
    workbook = xlrd.open_workbook(path)
    sheet1_conntent2 = workbook.sheet_by_index(0)
    Interface_Name = str(sheet1_conntent2.row_values(1)[2])
def Excel(path):
    workbook = xlrd.open_workbook(path)
    sheet1_conntent2 = workbook.sheet_by_index(0)
    fyfilename = str(sheet1_conntent2.row_values(1)[1])
    tests.Assertion_Generation_Tool.File_Header(fyfilename=fyfilename)
    # print(sheet1_conntent2.row_values(2,6))
    # print(sheet1_conntent2.cell(2, 6))
    for a in range(1, sheet1_conntent2.nrows):
        # print('a============>',a)
        # executions=a
        data1 = []
        data1.append(sheet1_conntent2.row_values(a))
        # print(data1)
        f = []
        for b in range(9, sheet1_conntent2.ncols):
            f.append(data1[0][b])
        url =data1[0][4]+data1[0][5]
        headers=eval(data1[0][6])
        # print ("headersheadersheadersheaders",headers)
        casename =str(data1[0][2])
        token_inherit = data1[0][8]

        getorpost=str(data1[0][3])
        token_inherit_data = sheet1_conntent2.col_values(8)
        print(token_inherit_data)
        print(data1)
        if "" == str(data1[0][7]):
            data4=""
        else:
            null=''
            data4 = eval(data1[0][7])
            # print ("testtesttesttest",data4)
            tests.Assertion_Generation_Tool.Generate_py_file(url=url, headers=headers, casename=casename, getorpost=getorpost, data=data4, allureAnnotation=f, fyfilename=fyfilename, token_inherit=token_inherit, token_inherit_data=token_inherit_data, executions=a)

Excel(path='Excel_test.xls')
# Excel(path='testcast.xls')
